import requests
def menu():
    print('----------------欢迎来到翻译界面-------------------')
    print('------------------功能选择------------------------')
    print('\t\t\t\t1.汉译英')
    print('\t\t\t\t2.英译汉')
    print('\t\t\t\t3.退出')
    print('-------------------------------------------------')

def yyh(url, head):
    while True:
        shuru = input("请输入你要翻译的英语:")
        zaihe = {
            "eng": 1,
            "ignore_trans": 0,
            "query": shuru
        }
        res = requests.post(url, headers=head, data=zaihe)
        data = res.json()['data']['fanyi']
        print("这是翻译结果:", data)
        question = input("是否继续(T/F):")
        if question=='T':
            continue
        else:
            menu()
            break

def hyy(url, head):
    while True:
        shuru = input("请输入你要翻译的汉语:")
        zaihe = {
            "eng": 0,
            "ignore_trans": 0,
            "query": shuru
        }
        res = requests.post(url, headers=head, data=zaihe)
        data = res.json()['data']['fanyi']
        print("这是翻译结果:", data)
        question = input("是否继续(T/F):")
        if question == 'T':
            continue
        else:
            menu()
            break


def main():
    url = 'https://fanyi.so.com/index/search?eng=1&validate=&ignore_trans=0&query=hello%0A'
    head = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Content-Length": "0",
        "Cookie": "QiHooGUID=82EE8F3700A54721C87221761C63ED71.1691378976054; Q_UDID=af16e2da-e0f6-64f5-b5b1-feda5f429310; __guid=144965027.1258885502628468000.1691378975653.8003; count=2",
        "Origin": "https://fanyi.so.com",
        "Pro": "fanyi",
        "Referer": "https://fanyi.so.com/",
        "Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
        "Sec-Ch-Ua-Mobile": "?0",
        "Sec-Ch-Ua-Platform": '"Windows"',
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
    }
    menu()
    while True:
        choice= int(input("请输入您想要的功能选择:"))
        if choice == 1:
            hyy(url, head)
        elif choice == 2:
            yyh(url, head)
        else:
             break

if __name__ == '__main__':
    main()